if exists (select 1
          from sysobjects
          where  id = object_id('bd_fn_datetimeToInt')
          and type in ('IF', 'FN', 'TF'))
   drop function bd_fn_datetimeToInt
go


create function bd_fn_datetimeToInt (@curDate DATETIME,@cardDate DATETIME)
RETURNS INT
BEGIN
  DECLARE @result INT, @day INT = 0

  SET @day = DATEDIFF(DAY, @curDate, @cardDate)

  SET @result = @day * 1440 + DATEPART(HOUR,@cardDate) * 60 + DATEPART(MINUTE,@cardDate)

  RETURN @result
END
go
